import {
  MiddlewareConsumer,
  Module,
  NestModule,
  RequestMethod,
} from '@nestjs/common';
import { UseAopService } from './use-aop.service';
import { UseAopController } from './use-aop.controller';
import { UseAopMiddleware } from './use-aop.middleware';

@Module({
  controllers: [UseAopController],
  providers: [UseAopService],
  exports: [UseAopService],
})
// 应用中间件
export class UseAopModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    // 应用到整个 controller
    // consumer.apply(UseAopMiddleware).forRoutes(UseAopController);

    // 应用到路由 get请求 /use-aop
    consumer.apply(UseAopMiddleware).forRoutes({
      path: '/use-aop',
      method: RequestMethod.GET,
    });
  }
}
